package com.baitengsoft.patentapimonitor.api.service.impl;

import com.baitengsoft.patentapimonitor.api.entity.ScheduleJobLogEntity;
import com.baitengsoft.patentapimonitor.api.model.param.ScheduleJobLogParam;
import com.baitengsoft.patentapimonitor.api.service.ScheduleJobLogService;
import com.baitengsoft.patentapimonitor.common.utils.PageResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * Created by Admin on 2018/1/10.
 */
@Service
public class ScheduleJobLogServiceImpl extends BaseServiceImpl<ScheduleJobLogEntity> implements ScheduleJobLogService {

    @Override
    public PageResult<ScheduleJobLogEntity> searchSJobLogByJobId(ScheduleJobLogParam param) {

        PageHelper.startPage(param.getPage(),param.getPageSize());
        Mapper mapperTk=getMapper();
        Example example=new Example(ScheduleJobLogEntity.class);
        example.setOrderByClause("createdate DESC");
        Example.Criteria criteria=example.createCriteria();
        criteria.andEqualTo("jobid",param.getJobId());
        List<ScheduleJobLogEntity> entities=mapperTk.selectByExample(example);
        PageInfo<ScheduleJobLogEntity> pageInfo=new PageInfo<>(entities);
        if(entities!=null&&entities.size()>0) return new PageResult<ScheduleJobLogEntity>(entities,param.getPage(),param.getPageSize(),(int)pageInfo.getTotal());
        return null;
    }
}
